<template>
  <div class="app-container">

    <!-- 添加或修改主体信息对话框 -->
    <div >
      <el-form ref="form" :model="form" :rules="rules" label-width="150px" style="width: 1300px;">
        <el-row>
          <el-col :span="8">
            <el-form-item label="主体名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="主题性质" prop="ztxzCode">
              <el-select v-model="form.ztxzCode" placeholder="请选择协议类型">
                <el-option label="家庭农场" value="1"></el-option>
                <el-option label="企业" value="2"></el-option>
                <el-option label="合作社" value="3"></el-option>
                <el-option label="其他" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="营业执照" prop="licenNo">
              <el-input v-model="form.licenNo" placeholder="请输入营业执照" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人" prop="contact">
              <el-input v-model="form.contact" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="企业地址" prop="addr">
              <el-input v-model="form.addr" placeholder="请输入企业地址" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="地理坐标" prop="jingDu">
              经度<el-input v-model="form.jingDu" placeholder="请输入经度" style="width: 100px" />
              维度<el-input v-model="form.weiDu" placeholder="请输入纬度" style="width: 100px" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="养殖证编号" prop="yangzhizNo">
              <el-input v-model="form.yangzhizNo" placeholder="请输入养殖证编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="苗种生产许可证号" prop="mzPermitNo">
              <el-input v-model="form.mzPermitNo" placeholder="请输入苗种生产许可证号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="主导产品" prop="productName">
              <el-input v-model="form.productName" placeholder="请输入主导产品" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="农安码" prop="nam">
              <el-input v-model="form.nam" placeholder="请输入农安码" />
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
    </div>
      <div slot="footer" class="dialog-footer" >
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>

  </div>
</template>

<script>
  import { getUserProfile } from "@/api/system/user";
  import { getInfoByUser, updateMainInfo } from "@/api/busi/mainInfo";

export default {
  name: "MainInfo",
  components: {
  },
  data() {
    return {
      user:null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getUser();
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.handleUpdate();
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        ztxzCode: null,
        licenNo: null,
        contact: null,
        phone: null,
        addr: null,
        jingDu: null,
        weiDu: null,
        yangzhizNo: null,
        mzPermitNo: null,
        productName: null
      };
      this.resetForm("form");
    },
    /** 修改按钮操作 */
    handleUpdate() {
      this.reset();
      getInfoByUser({userId:this.user.userId}).then(response => {
        this.form = response.data;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMainInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
            });
          }
        }
      });
    },

  }
};
</script>
